﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>数据统计布局配置</title>
    <meta charset="utf-8" />
    <base target="_self" />
    @Html.Raw(ViewBag.CPWebRootPath)
    @Html.Raw(ViewBag.CPCurUserId)
    @Html.Raw(ViewBag.CPCurUserIden)
    <!-- 下面两句代码是做手机适配用的 ， 加上之后手机网页就会自动适配-->
    <!--解决安卓手机点击文本框，会自动放大网页的问题-->
    <meta name="viewport" content="width=device-width">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <script type="text/javascript" src="../../Plat/Common/JS/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="../../Plat/Common/JS/Common.js"></script>

    <!--阿里图标-->
    <link rel="stylesheet" href="../../Style/AibabaIcon/iconfont.css">
    <link href="../../Style/@ViewBag.CPSkin/Common.css" type="text/css" rel="stylesheet" />
    <!--layer ui-->
    <link rel="stylesheet" href="../../Plat/Common/layui/css/layui.css" media="all">
    <script type="text/javascript" charset="utf-8" src="../../Plat/Common/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../Plat/Common/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="../../Plat/Common/ueditor/lang/zh-cn/zh-cn.js"></script>

    <style type="text/css">
        div {
            width: 100%;
        }
    </style>
</head>
<body style="overflow:auto;">
    <div style="text-align:right;width:100%; border-bottom:1px solid #d4d4d4; height:50px;line-height:50px;
margin-bottom:5px;">
        双击在光标指定处插入
        <button onclick="SaveData()" class="layui-btn layui-btn-normal" style="margin-right:50px;">确定并返回</button>
    </div>
    <div style="margin:0px;  padding:0px;float:left;width:10px; text-align:left;">&nbsp;</div>
    <div id="divLeft" style="margin:0px;  padding:0px;float:left;width:18%; text-align:left; overflow:auto; ">

    </div>
    <div id="divRight" style="margin:0px; padding:0px;float:left;width:80%; ">
        <script id="editor" type="text/plain" style="width:100%;height:500px;">
        </script>
    </div>
    <script type="text/javascript">

        function AddField(Id, Title, StatisticsHeight)
        {
        //var sValue = "{@@" + tableName + "." + fieldName + "@@}";
            var sValue = "<div id= 'divStatistics_" + Id + "' style= 'height:" + StatisticsHeight + "px; width:100%;' > " + Title +"</div>";

            UE.getEditor('editor').execCommand('insertHtml', sValue);
        }
        var ssHTML = "";
        function SaveData()
        {
            var sHTML = UE.getEditor('editor').getContent();
            parent.CPFormGlobal_Scope.SetFieldValue("DataV_Layout", "LayoutHTML", 0, sHTML);
            parent.CloseNewModel();
            
        }
        //全局传入参数start 
        var CPDataVGlobal_DataVCode = $.CPGetQuery("DataVCode"); if (CPDataVGlobal_DataVCode == null || CPDataVGlobal_DataVCode == undefined) CPDataVGlobal_DataVCode = "";
        var CPDataVGlobal_LayoutCode = $.CPGetQuery("LayoutCode"); if (CPDataVGlobal_LayoutCode == null || CPDataVGlobal_LayoutCode == undefined) CPDataVGlobal_LayoutCode = "";
        //全局传入参数end
        $(function () {
            $("#editor").height($(window).height() - 200);
            $("#divLeft").height($(window).height() - 60);
            //实例化编辑器
            //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
            var ue = UE.getEditor('editor', {
                allowDivTransToP: false,
                allHtmlEnabled: true,
                disabledTableInTable: false
            });
            ue.ready(function () {
                var getDataUrl = CPWebRootPath + "/api/DataVEngine/GetDataVInfoByDataVId?DataVCode=" + CPDataVGlobal_DataVCode + "&CurUserId=" + CPCurUserId + "&CurUserIden=" + CPCurUserIden;
                //为了表达式，需要把URL里其它字段再加上
                //再加其它参数
                var sResultArray = CPGetQueryString();
                for (var mm = 0; mm < sResultArray.length; mm++) {
                    var tempSarray = sResultArray[mm].split('=');
                    if (tempSarray[0].toLowerCase() == "datavcode"
                        || tempSarray[0].toLowerCase() == "curuserid"
                        || tempSarray[0].toLowerCase() == "curuseriden"
                    )
                        continue;
                    getDataUrl += "&" + sResultArray[mm];
                }
                $.getJSON(getDataUrl, function (data) {
                    if (data.Result == false) {
                        alert(data.ErrorMsg);
                        return false;
                    }
                    var CPDataVGlobal_DataVObj = data.DataV;
                    console.log(CPDataVGlobal_DataVObj);
                    var sHTML = ""; 
                    $.each(CPDataVGlobal_DataVObj.StatisticsCol, function (nIndexStatistics, nObjStatistics) {
                        //sHTML += "<div id='divStatistics_" + nObjStatistics.Id + "' style='height:100% width:100%;'>" + nObjStatistics.StatisticsTitle +"</div>";
                        sHTML += "<div style=\"margin-top:5px; \"><button ondblclick=\"AddField('" + nObjStatistics.Id + "','" + nObjStatistics.StatisticsTitle + "','" + nObjStatistics.StatisticsHeight + "')\" class=\"layui-btn layui-btn-normal\">" + nObjStatistics.StatisticsTitle  + "</button></div>";
                    });
                    $("#divLeft").html(sHTML);
                    //UE.getEditor('editor').setContent(data.View.FormViewHTML, false);
                    //  UE.getEditor('editor').execCommand('insertHtml', data.View.FormViewHTML)
                    var oldValue = parent.CPFormGlobal_Scope.GetFieldValue("DataV_Layout", "LayoutHTML", 0);
                    UE.getEditor('editor').setContent(oldValue);
                });
            });


        });



    </script>
</body>
</html>
